
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>用户管理</title>
    <%@include file="../../system/sys_common_head.jsp"%>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名/身份证</label>
                <div class="layui-input-inline">
                    <input type="text" name="stuIdcard" placeholder="" class="layui-input">
                </div>

                <label class="layui-form-label">缴费状态</label>
                <div class="layui-input-inline">
                    <select name="status" id="status" lay-filter="status">
                        <option value="">请选择</option>
                        <option value="0">未缴费</option>
                        <option value="1">已缴费</option>
                        <option value="3">已取消</option>
                        <option value="4">已退费</option>
                    </select>
                </div>

                <label class="layui-form-label">学校</label>
                <div class="layui-input-inline">
                    <select name="schoolId" id="schoolId" lay-filter="schoolId">
                        <option value="">请选择</option>
                        <option value="1">江西赣州技师学院</option>
                        <option value="2">赣州农业学校</option>
                    </select>
                </div>

                <label class="layui-form-label">专业</label>
                <div class="layui-input-inline">
                    <select name="majorId" id="majorId" lay-filter="status">
                        <option value="">请选择</option>
                        <c:forEach var="major" items="${majorList}"><option value="${major.id}">${major.majorName}</option></c:forEach>
                    </select>
                </div>

                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="preRegistration-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
                <button class="pear-btn pear-btn-md pear-btn-danger" onclick="searchPill()" type="button">
                    <i class="layui-icon layui-icon-search"></i>
                    更新缴费记录
                </button>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="preRegistration-table" lay-filter="preRegistration-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="preRegistration-toolbar">

</script>

<script type="text/html" id="show-enable">

    {{#
        if(d.status == 3){
    }}
    已取消
    {{#
        }else{


        let date = new Date(timestampToTime(d.createTime)).getTime();
        let dateNow = new Date().getTime();
        if((dateNow - date)/1000 > 172800 && d.status != '1'){
    }}

    <input type="checkbox" name="enable" value="{{d.billNo}}" lay-skin="switch" lay-text="已取消|取消" lay-filter="role-enable" >
    {{#
        }
    }
    }}


</script>

<!-- 每行操作栏 -->
<script type="text/html" id="data-bar">
    {{#if (d.status == '1') { }}
    已缴费
    {{# }else{ }}
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="relodJF">同步缴费</button>
    <shiro:hasPermission name="student:prelog:delete">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="delJF">删除订单</button>
    </shiro:hasPermission>
    {{# } }}
</script>

<script>
    layui.use(['table', 'form', 'jquery','common','layer', 'util'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;
        var util = layui.util;

        let MODULE_PATH = "/student/prelog/";

        let cols = [
            [
                {field: 'id', title: 'id',hide:true},
                {field: 'stuName', title: '学生姓名'},
                {field: 'stuIdcard', title: '身份证号',width:200},
                {field: 'billMoney', title: '支付金额',width:100},
                {field: 'phone', title: '联系电话'},
                {field: 'pPhone', title: '家长电话'},
                {field: 'majorName', title: '专业'},
                {field: 'billNo', title: '支付id',hide:true},
                {field: 'score', title: '分数'},
                {field: 'status', title: '缴费状态',width:100,templet:function(d){
                        if(d.status == 1){
                            return "缴费成功";
                        }else if(d.status == 4){
                            return "已退费";
                        }else{
                            return "未缴费";
                        }}
                },
                {title: '是否取消', align: 'center', templet: '#show-enable'},
                // {field: 'sendJson', title: '发送的字符串'},
                {field: 'createTime', title: '发送时间',templet:function(d){
                        return timestampToTime(d.createTime);
                    }},
                {field: 'memo', title: '备注',edit: 'text'},
                // {field: 'memo', title: '备注',edit: 'text'},
                {title: '操作', fixed: 'right', width: 195, align:'center', toolbar: '#data-bar'}
            ]
        ]

        table.render({
            elem: '#preRegistration-table',
            url: MODULE_PATH + 'list',
            page: true,
            cols: cols,
            // editTrigger: 'dblclick', //双击编辑
            skin: 'line',
            limits:	[10,30,60,100,200,500,1000],
            limit:'30',
            toolbar: '#preRegistration-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        // 单元格编辑后的事件
        table.on('edit(preRegistration-table)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改值为：'+ util.escape(value));
            let loading = layer.load();
            $.ajax({
                url: MODULE_PATH + 'update',
                data: {
                    id:data.id,
                    memo:value
                },
                dataType: 'json',
                // contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 0) {
                        layer.msg(result.msg, {icon: 1, time: 3000});
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 3000});
                    }
                },error:function( e ){
                    layer.close(loading);
                    layer.msg("系统错误", {icon: 2, time: 3000});
                }
            })
        });

        table.on('tool(preRegistration-table)', function (obj) {
            if (obj.event === 'relodJF') {
                window.relodJF(obj);
            }else if (obj.event === 'delJF') {
                window.delJF(obj);
            }
        });

        form.on('submit(preRegistration-query)', function (data) {
            table.reload('preRegistration-table', {where: data.field})
            return false;
        });

        form.on('switch(role-enable)', function (obj) {
            layer.confirm('确定要取消该学生的缴费吗？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();

                $.ajax({
                    url: "<%=request.getContextPath()%>/student/preregistration/cancelFree",
                    dataType: 'json',
                    data:{billNo:obj.value},
                    type: 'get',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                // obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })

            })

        });

        window.relodJF = function(obj) {
            let loading = layer.load();
            $.ajax({
                url: "<%=request.getContextPath()%>/student/preregistration/reloadFeeStatus",
                data:{
                    billNo:obj.data['billNo']
                },
                dataType: 'json',
                type: 'get',
                success: function(result) {
                    layer.close(loading);
                    if (result.code == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            layui.table.reload("preRegistration-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
        }

        window.searchPill = function() {
            let loading = layer.load();
            $.ajax({
                url: "<%=request.getContextPath()%>/student/preregistration/roledLogAll",
                dataType: 'json',
                type: 'get',
                success: function(result) {
                    layer.close(loading);
                    if (result.code == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            layui.table.reload("preRegistration-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
        }

        window.delJF = function(obj) {
            let loading = layer.load();
            $.ajax({
                url: "<%=request.getContextPath()%>/student/preregistration/delFeeStatus",
                data:{
                    billNo:obj.data['billNo']
                },
                dataType: 'json',
                type: 'get',
                success: function(result) {
                    layer.close(loading);
                    if (result.code == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            layui.table.reload("preRegistration-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
        }

        form.on('select(schoolId)', function(data){
            initMajorBySchoolId($("#schoolId").val())
        });
        // 初始化专业
        window.initMajorBySchoolId = function(schoolId){
            $.ajax({
                url: '<%=request.getContextPath()%>/common/queryMajorBySchoolId',
                dataType: 'json',
                data:{schoolId:schoolId},
                type: 'get',
                success: function (result) {
                    var inHtml = "<option value=''>请选择</option>";
                    // majorList = result;
                    for(var i = 0;i < result.length; i++){
                        inHtml = inHtml+"<option value='"+result[i].id+"'>"+result[i].majorName+"</option>"

                    }
                    $("#majorId").html(inHtml);
                    form.render('select'); //刷新select选择框渲染
                }
            })
        }

    })
</script>
</html>